package com.payment.ktb.activity.main4;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyco.dialog.listener.OnOperItemClickL;
import com.flyco.dialog.widget.ActionSheetDialog;
import com.payment.ktb.R;
import com.payment.ktb.activity.BaseActivity;
import com.payment.ktb.activity.LoginActivity;
import com.payment.ktb.constants.ConstantsUser;
import com.payment.ktb.utils.PhtotUtils;
import com.payment.ktb.utils.SharedPreferencesUtils;
import com.squareup.picasso.Picasso;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by syd on 2016/6/3.
 */
public class PersionalinfoActivity extends BaseActivity {



    File file;

    @BindView(R.id.iv_personalinfo_head)
    ImageView iv_personalinfo_head;
    @BindView(R.id.tv_personalinfo_birthday)
    TextView tv_personalinfo_birthday;
    @BindView(R.id.tv_personalinfo_gender)
    TextView tv_personalinfo_gender;
    @BindView(R.id.tv_persionalinfo_nickname)
    TextView tv_persionalinfo_nickname;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personalinfo);
        ButterKnife.bind(this);
        initTitle("个人信息");
        file = new File(Environment.getExternalStorageDirectory(), SharedPreferencesUtils.getString(ConstantsUser.phone) + "avatar.png");

        initData();
    }

    /**
     *
     */
    private void initData() {
        tv_persionalinfo_nickname.setText(SharedPreferencesUtils.getString(ConstantsUser.userNick));


        if (SharedPreferencesUtils.getString((SharedPreferencesUtils.getString(ConstantsUser.phone) + ConstantsUser.userStatus)).equals("20")){
            if ("1".equals(SharedPreferencesUtils.getString(ConstantsUser.sex))) {
                tv_personalinfo_gender.setText("男");
            }else if ("2".equals(SharedPreferencesUtils.getString(ConstantsUser.sex))) {
                tv_personalinfo_gender.setText("女");
            }
        } else {
            tv_personalinfo_gender.setText("保密");
        }


        tv_personalinfo_birthday.setText(SharedPreferencesUtils.getString(ConstantsUser.birthday));
    }


    @OnClick({R.id.ll_persionalinfo_avatar,R.id.ll_personalinfo_nickname})
    public void clickEvent(View view) {

        switch (view.getId()) {

            //avatar
            case R.id.ll_persionalinfo_avatar:
              startActivity(PortraitActivity.class);
                break;
            //nickname
            case R.id.ll_personalinfo_nickname:
                startActivity(NicknameActivity.class);
                break;

        }
    }





    @Override
    protected void onResume() {
        super.onResume();
        file = new File(Environment.getExternalStorageDirectory(), SharedPreferencesUtils.getString(ConstantsUser.phone) + "avatar.png");
      if (!TextUtils.isEmpty( SharedPreferencesUtils.getString(SharedPreferencesUtils.getString(ConstantsUser.phone) + ConstantsUser.picHeader))){
            Picasso.with(mContext).load(SharedPreferencesUtils.getString(SharedPreferencesUtils.getString(ConstantsUser.phone) + ConstantsUser.picHeader)).fit().into(iv_personalinfo_head);
        }else if (file != null && file.exists()) {
          iv_personalinfo_head.setImageBitmap(BitmapFactory.decodeFile(file.getPath()));
      }
    }


}
